package com.test.cordova.mvp.base;

import com.google.gson.Gson;
import com.test.cordova.mvp.base.net.RetrofitServiceManager;

import okhttp3.RequestBody;
import retrofit2.Retrofit;

/**
 * Created by Administrator on 2019/3/11 0011.
 */

public abstract class BaseModel <T> {

    protected final Retrofit retrofit;
    private Class<T> t;

    public BaseModel() {
        retrofit = RetrofitServiceManager.getInstance().getRetrofit();
        initRequest();
    }

    protected T createRequest(){
        return retrofit.create(t);
    }

    protected RequestBody getRequestBody(Object obj) {
        String route = new Gson().toJson(obj);
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), route);
        return body;
    }

    public abstract void initRequest();

    public abstract void onDestory();

}
